home *** CD-ROM | disk | FTP | other *** search
- { BiNHEX unit (c) 1995 by Paradise }
- { (a.k.a. Marcin Jaskowiak) }
- { paradise@bachus.umcs.lublin.pl }
- { paradise@ajax.umcs.lublin.pl }
- { paradise@anon.penet.fi }
- { }
- { Conversions : }
- { BYTE -> BIN }
- { WORD -> BIN }
- { BYTE -> HEX }
- { WORD -> HEX }
- { BYTE -> DEC }
- { WORD -> DEC }
- { BYTE -> ASC }
- { }
- { You can use this piece of code }
- { in your programs, but remember }
- { to credit or greet me :) }
- { }
-
- unit BINHEX;
-
- {■■■} interface {■■■}
-
- function Word2Bin(W: Word): string;
- function Byte2Bin(B: Byte): string;
- function Word2Hex(W: Word): string;
- function Byte2Hex(B: Byte): string;
- function Word2Dec(W: Word): string;
- function Byte2Dec(B: Byte): string;
- function Byte2Asc(B: Byte): string;
-
- {■■■} implementation {■■■}
-
- const
- Digits : string ='0123456789ABCDEF';
-
- function Word2Bin(W: Word): string;
- var
- s : String;
- i,j,k: Word;
- begin
- k:=1; s:='';
- for i:=$0 to $f do
- begin
- if (W and k)>0 then s:='1'+s
- else s:='0'+s;
- k:=k*2;
- end;
- Word2Bin:=s+'b';
- End;
-
- function Byte2Bin(B: Byte): string;
- var
- s : String;
- i,j,k: Word;
- begin
- k:=1; s:='';
- for i:=$0 to $7 do
- begin
- if (B and k)>0 then s:='1'+s
- else s:='0'+s;
- k:=k*2;
- end;
- Byte2Bin:=s+'b';
- End;
-
- function Word2Hex(W: Word): string;
- begin
- Word2Hex:='0'+Digits[hi(W) and $f0 shr 4+1]+Digits[hi(W) and $0f+1]
- +Digits[lo(W) and $f0 shr 4+1]+Digits[lo(W) and $0f+1]+'h';
- End;
-
- function Byte2Hex(B: Byte): string;
- begin
- Byte2Hex:='0'+Digits[B and $f0 shr 4+1]+Digits[B and $0f+1]+'h';
- End;
-
- function Word2Dec(W: Word): string;
- var
- ss : string;
- begin
- Str(W,ss);
- Word2Dec:=ss;
- end;
-
- function Byte2Dec(B: Byte): string;
- var
- ss : string;
- begin
- Str(B,ss);
- Byte2Dec:=ss;
- end;
-
- function Byte2Asc(B: Byte): string;
- begin
- Byte2Asc:=''''+Chr(B)+'''';
- end;
-
-
- { end of code! }
- end.
-
-